<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" layout:decorator="base/layout.html">


    <!-- start: Content -->
    <div layout:fragment="content" class="main ">

        <div class="row">
            <div class="col-lg-12">
                <ol class="breadcrumb">
                    <li><i class="fa fa-home"></i><a href="index.html">主页</a></li>

                    <li><i class="fa fa-indent"></i>添加教师信息</li>
                </ol>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h2><i class="fa fa-indent red"></i><strong>添加教师信息</strong></h2>
                    </div>
                    <div class="panel-body">
                        <form id="modularForm" action="" method="post" enctype="multipart/form-data" class="form-horizontal ">

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">姓名</label>
                                <div class="col-md-9">
                                    <input type="text" id="text-input" name="name" class="form-control" placeholder="姓名">
                                    <span class="help-block">请输入姓名</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">工资</label>
                                <div class="col-md-9">
                                    <input type="text" id="text-input" name="money" class="form-control" placeholder="工资">
                                    <span class="help-block">请输入工资</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">科目</label>
                                <div class="col-md-9">
                                    <input type="text" id="text-input" name="subject" class="form-control" placeholder="科目">
                                    <span class="help-block">请输入科目</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">电话</label>
                                <div class="col-md-9">
                                    <input type="text" id="text-input" name="phoneNumber" class="form-control" placeholder="电话">
                                    <span class="help-block">请输入电话</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="file">附件上传</label>
                                <input type="file" id="file" name="file" class="form-control">
                                <input type="hidden" id="attachmentName" name="attachmentName">
                            </div>

                            <br>

                    </div>
                    <div class="panel-footer">
                        <button id="submitBtn" type="button" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> 提交</button>
                        <button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i>重置</button>
                    </div>
                    </form>
                </div>
            </div>


        </div><!--/.row-->


        <script>

            $("#submitBtn").click(function () {
                $.ajax({
                    url:'add',
                    type:'post',
                    data:$('#modularForm').serialize(),
                    success:function (data) {
                        layer.msg("添加成功");
                        setTimeout(function () {
                            window.location = ("teacher")
                        },1500);
                    }
                })
            })

            $(function() {
                // 文件上传
                $("#file").change(function() {
                    var formData = new FormData();
                    formData.append("file", this.files[0]);
                    
                    $.ajax({
                        url: '/teachers/uploadFile',
                        type: 'POST',
                        data: formData,
                        processData: false,
                        contentType: false,
                        success: function(res) {
                            if(res.code == 0) {
                                $("#attachmentName").val(res.originalFileName);
                                layer.msg("上传成功");
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                });
            });

            // 删除文件
            function deleteFile(fileName, teacherId) {
                layer.confirm('确定要删除此附件吗？', {
                    btn: ['确定','取消']
                }, function(){
                    $.ajax({
                        url: '/teachers/deleteFile',
                        type: 'POST',
                        data: {
                            fileName: fileName,
                            teacherId: teacherId
                        },
                        success: function(res) {
                            if(res.code == 0) {
                                layer.msg("删除成功");
                                location.reload();
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                });
            }

        </script>

    </div>




    <!-- end: Content -->

